<template>
	<view class="min100 plr-30 pb-100 bg " >
		<view class="flex radius-45 ptb-12 plr-10" style="">
			<view class=" flex toptitbox flex-between">
				<view class="flex radius-45 plr-10 tabbox">
					<view :class="['ptb-20','mlr-10','midItem',midIndex==0?'midActive':'']" @click="changeMid(0)">
						藏品
						<view class="line" v-if="midIndex==0"></view>
					</view>
					<view :class="['ptb-20','mlr-10','midItem',midIndex==1?'midActive':'']" @click="changeMid(1)">
						盲盒
						<view class="line" v-if="midIndex==1"></view>
					</view>
				</view>
			</view>
		</view>
		<view class="" v-if="isshow==0">
			<view class="searchbox flex flex-start mt-20">
				<view class="selectbox ml-10 flex flex-between">
					<view v-for="item in select_list"
						:class="['plr-20','ptb-12',item.active==true?'selectitem':'selectitem1']"
						@click="navigation(item)">{{item.name}}</view>
				</view>
			</view>
			<view class=" ptb-20">
				<view class="min100 plr-30  ptb-40 bg">
					<view class="flex flex-start flex-top mb-30 radius-20 plr-30 ptb-30 "
						v-for="(item,index) in notice_list" style="background-color: #f5f5f5;" :key="index"
						@click="tonotice(item.id)">
						<image :src="item.image" class="itemImg mr-20 radius-20"></image>
						<view style="width:72%;" class="">
							<view class="flex1 flex-between" style="align-items: center;">
								<view class="fw size-28">
									{{item.name}}
								</view>
								<view class="size-44">
									￥{{item.price}}
								</view>
							</view>
							<view class="size-24 mt-20  " style="text-align: right;">
								<text v-if="item.status==0">待付款</text>
								<text v-if="item.status==1">已付款</text>
								<text v-if="item.status==2">已取消</text>
							</view>

							<view class=" size-20 mt-20" style="text-align: right;">
								{{item.create_time}}
							</view>
							<view class="flex mt-40 btnWrap" style="float: right;" v-if="item.status==0">
								<u-button @click="cancelOrder(item.id)" round class="transferBtn mr-30">取消订单</u-button>
								<u-button round class="saleBtn" @click="payOrder(item.order_id,item.type)">去支付</u-button>
							</view>

						</view>

					</view>
				</view>
			</view>
		</view>
		<view class="" v-if="isshow==1">
			<view class="searchbox flex flex-start mt-20">
				<view class="selectbox ml-10 flex flex-between">
					<view v-for="item in select_list1"
						:class="['plr-20','ptb-12',item.active==true?'selectitem':'selectitem1']"
						@click="navigation(item)">{{item.name}}</view>
				</view>
			</view>
			<view class=" ptb-20">
				<view class="min100 plr-30  ptb-40 bg">
					<view class="flex flex-start flex-top mb-30 radius-20 plr-30 ptb-30 "
						v-for="(item,index) in Journalism_list" style="background-color: #f5f5f5;" :key="index"
						@click="tonotice(item.id)">
						<image :src="item.image" class="itemImg mr-20 radius-20"></image>
						<view style="width:72%;" class="">
							<view class="flex1 flex-between">
								<view class="fw size-28">
									{{item.name}}
								</view>
								<view class="size-44">
									￥{{item.price}}
								</view>
							</view>
							<view class="size-24 mt-20  " style="text-align: right;">
								<text v-if="item.status==0">待付款</text>
								<text v-if="item.status==1">已付款</text>
								<text v-if="item.status==2">已取消</text>
							</view>

							<view class=" size-20 mt-20" style="text-align: right;">
								{{item.create_time}}
							</view>
							<view class="flex mt-40 btnWrap" style="float: right;" v-if="item.status==0">
								<u-button @click="cancelOrder(item.id)" round class="transferBtn mr-30">取消订单</u-button>
								<u-button round class="saleBtn" @click="payOrder(item.order_id,item.type)">去支付</u-button>
							</view>

						</view>

					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		globalData
	} from "@/App.vue"
	import empty from "../../components/empty.vue"
	export default {
		components: {
			empty,
		
		},
		data() {
			return {
				blindBoxheight: '',
				active: true,

				item: '',
				// 辟谣墙列表
				putarr: [

				],

				isshow: 0,
				Journalism_list: [],
				// 平台公告列表
				notice_list: [],
				// 平台公告分类
				select_list: [{
					name: '全部',
					id: '',
					active: true,
				}, 
				{
					name: '已卖出',
					id: 3,
				}, 
				{
					name: '待付款',
					id: 0,
				}, 
				{
					name: '已付款',
					id: 1,
				}, {
					name: '已取消',
					id: 2,
				}],
				select_list1: [{
					name: '全部',
					id: '',
					active: true,
				}, 
				{
					name: '已卖出',
					id: 3,
				}, 
				{
					name: '待付款',
					id: 0,
				}, {
					name: '已付款',
					id: 1,
				}, {
					name: '已取消',
					id: 2,
				}],
				// 新闻发声列表
				journalismarr: [],
				// 新闻发声分类
				Journalism_list: [],
				poparr: [],
				show: false,
				rowStyle: 2,
				midIndex: 0,
				query: {
					page: 1,
					pagesize: 10,
					search: "",
					time_order: '',
					price_order: '',
				},
				status: 'more',
				list: [],
				goods_id: [],
				wall: '',
				id: 0
			}
		},
		onLoad() {
			let _that = this;
			uni.getSystemInfo({
				success(e) {
					// console.log(e.statusBarHeight, '123122222222222222222222');
					if (e.platform == "ios" || e.platform == "devtools") {
						_that.blindBoxheight = e.statusBarHeight + 45;
					} else {
						_that.blindBoxheight = e.statusBarHeight + 50;
					}
				}
			})
			
			this.$http('api/orders/goodsOrderList', {
				page: 1,
				pagesize: 10,
				status: ''
			}).then(res => {
				this.notice_list = res.data
				console.log(this.notice_list);
			})
			
			// console.log(getApp().globalData);
		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function () {
				uni.stopPullDownRefresh();
				
			}, 1000);
			this.$http('api/orders/goodsOrderList', {
				page: 1,
				pagesize: 10,
				status: ''
			}).then(res => {
				this.notice_list = res.data
				// console.log(this.notice_list);
			})
		},
		onShow() {
			// this.init();
			// // tisshow=0,

			// 公告初渲染
			this.isshow=0
			this.$http('api/orders/goodsOrderList', {
				page: 1,
				pagesize: 10,
				status: ''
			}).then(res => {
				this.notice_list = res.data
				console.log(this.notice_list);
			})
			this.id=0
		},
		onHide() {
			this.midIndex = 0;
			this.flag = false;
			this.status = 'more';
			this.list = [];
			this.query = {
				page: 1,
				pagesize: 10,
				search: "",
				time_order: '',
				price_order: ''
			}
		},
		onReachBottom() {
			if (this.wall >= this.query.pagesize) {
				this.feedBackList()
			} else {
				console.log(1);
			}
		},

		methods: {
			// 我的订单跳转
			tonotice(order_id) {
				console.log(this.id,this.isshow);
				// console.log(this.isshow)
				if(this.isshow==0){
					if(this.id==3){
						// console.log('已卖出')
						uni.navigateTo({
						url: '/pages/pay/sellOrder?order_id=' + order_id+'&isshow='+this.isshow
						})
					}else{
						// console.log('其他')
						uni.navigateTo({
							url: '/pages/pay/collectPay?order_id=' + order_id+'&isshow='+this.isshow
						})
					}
					
				}else if(this.isshow==1){
					console.log(this.id)
					if(this.id==3){
						// console.log('已卖出')
						uni.navigateTo({
						url: '/pages/pay/sellOrder?order_id=' + order_id+'&isshow='+this.isshow
						})
					}else{
						// console.log('其他')
						uni.navigateTo({
							url: '/pages/pay/collectPay?order_id=' + order_id+'&isshow='+this.isshow
						})
					}
				}
				
			},
			// 取消订单
			cancelOrder(id) {
				let _this = this;
				if (this.midIndex == 0) {
					// 藏品
					uni.showModal({
						title: '提示',
						content: '确定取消订单?',
						confirmColor: '#EFAA1C',
						success: function(res) {
							if (res.confirm) {
								_this.$http('api/orders/cancelGoodsOrder', {
									id: id
								}, 'POST').then(res => {
									_this.list = [];
									_this.page = 1;
									_this.current = 3;
									_this.status = 2;
									_this.init();

								})
							} else if (res.cancel) {
								uni.showToast({
									title: "取消操作!",
									icon: "none"
								})
							}
						}
					});
				} else {
					// 盲盒
					uni.showModal({
						title: '提示',
						content: '确定取消订单?',
						confirmColor: '#EFAA1C',
						success: function(res) {
							if (res.confirm) {
								_this.$http('api/orders/cancelBoxOrder', {
									id: id
								}, 'POST').then(res => {
									_this.list = [];
									_this.page = 1;
									_this.current = 3;
									_this.status = 2;
									_this.init();
								})
							} else if (res.cancel) {
								uni.showToast({
									title: "取消操作!",
									icon: "none"
								})
							}
						}
					});
				}

			},
			// 去支付
			payOrder(order_id,type) {
				console.log(this.midIndex)
				if (this.midIndex == 0) {
					console.log(type)
					if(type == 1){
						uni.navigateTo({
							url: '../pay/mallPay?order_id=' + order_id+'&isshow=0'
						})
					}else{
						uni.navigateTo({
							url: '../pay/collectPay?order_id=' + order_id+'&isshow=0'
						})
					}
					//藏品
					
				} else {
					// 盲盒
					uni.navigateTo({
						url: '../pay/collectPaybox?order_id=' + order_id+'&isshow=1'
					})
				}
			},
			handlesearch() {
				uni.navigateTo({
					url: '/pages/market/marketSearch'
				})
			},



			toRumor(item) {
				var item = JSON.stringify(item)
				uni.navigateTo({
					url: '/pages/market/rumor_detail?item=' + item
				})
			},

			// 辟谣墙跳转
			toquestions() {
				uni.navigateTo({
					url: '/pages/market/question'
				})
			},
			// 二级tab点击
			navigation(item) {
				// console.log(this.isshow)
				if (this.isshow == 0) {
					this.id = item.id
					// console.log(this.id)
					if(this.id!==3){
						this.$http('api/orders/goodsOrderList', {
							page: 1,
							pagesize: 10,
							status: this.id
						}).then(res => {
							this.notice_list = res.data
							console.log(this.notice_list);
						})
					}else{
						
						this.$http('api/orders/goodsOrderSellList', {
							page: 1,
							pagesize: 10,
							status: ''
						}).then(res => {
							this.notice_list = res.data
							console.log(this.notice_list);
						})
					}
					

					for (let i = 0; i < this.select_list.length; i++) {
						this.select_list[i].active = false
					}

					item.active = true
				} else if (this.isshow == 1) {
					this.id = item.id
					if(this.id!==3){
						this.$http('api/orders/boxOrderList', {
							page: 1,
							pagesize: 10,
							status: this.id
						}).then(res => {
							this.Journalism_list = res.data
							console.log(this.Journalism_list);
						})
					}else{
						this.$http('api/orders/boxOrderSellList', {
							page: 1,
							pagesize: 10,
							status: ''
						}).then(res => {
							this.Journalism_list = res.data
							console.log(this.Journalism_list);
						})
					}

					for (let i = 0; i < this.select_list1.length; i++) {
						this.select_list1[i].active = false
					}
					item.active = true
				}


			},


			// 选择平台公告还是新闻发生还是辟谣墙
			changeMid(index) {
				this.isshow = index
				this.midIndex = index;
				if (this.midIndex == 0) {
					// 公告初渲染
					this.$http('api/orders/goodsOrderList', {
						page: 1,
						pagesize: 10,
						status: ''
					}).then(res => {
						this.notice_list = res.data
						// console.log(this.notice_list);
					})

				} else if (this.midIndex == 1) {
					console.log(1);
					this.$http('api/orders/boxOrderList', {
						page: 1,
						pagesize: 10,
						status: ''
					}).then(res => {
						this.Journalism_list = res.data
						// console.log(this.notice_list);
					})
					
				}
				this.list = [];
				this.query = {
					page: 1,
					pagesize: 10,
					search: "",
					time_order: '',
					price_order: ''
				};

			},
			init() {
				if (this.midIndex == 0) {
					this.$http('api/orders/goodsOrderList', {
						page: 1,
						pagesize: 10,
						status: ''
					}).then(res => {
						this.notice_list = res.data
						console.log(this.notice_list);
					})
				} else if (this.midIndex == 1) {
					this.$http('api/orders/boxOrderList', {
						page: 1,
						pagesize: 10,
						status: this.id
					}).then(res => {
						this.Journalism_list = res.data
						console.log(this.Journalism_list);
					})
				}
			},


		}
	}
</script>
<style lang="less" scoped>
	page {
		background-color: #fff;
	}

	::v-deep  .u-tab-item {
		// border: 2px solid #999;
		border-radius: 30px;
		margin: 0 20px 0 0;
		font-weight: 100 !important;

	}

	.itemImg {
		width: 260rpx;
		height: 220rpx;
	}

	.btnWrap {
		::v-deep .u-tab-bar {
			// margin: 0 0 0 -7px !important;

		}

		::v-deep  uni-button {
			height: 60rpx !important;
			padding: 0 30rpx !important;
			font-size: 22rpx;
		}

		.transferBtn {
			background: #44ACFF;
			color: #fff;
		}

		.saleBtn {
			background: transparent;
			border: 1rpx solid #fff;
		}
	}

	.midItem {
		width: 80rpx;
		height: 70rpx;
		color: #999;
		font-size: 28rpx;
		text-align: center;
	}



	.midActive {
		// border-bottom: 2px solid #000;
		// border: 2px solid #000;
		// color: #000;
		// border-bottom:1px solid #000;
	}

	.midActive1 {

		// border: 2px solid #000;
		// color: #000;
		// border-bottom:1px solid #000;
	}





	.contbox {
		.contentitem {
			border-bottom: 1rpx solid #E0E0E0;

			.imgbox {
				height: 220rpx;
				overflow: hidden;

				image {
					width: 100%;
				}
			}

			.leftbox {
				.text_title {
					font-weight: 600;
				}

				.tipsbox {
					margin-top: 100rpx;
					font-size: 12rpx;

					.tipsborder {
						border: 1rpx solid rgb(108, 126, 205);
						border-radius: 10rpx;
						color: rgb(108, 126, 205);
						background-color: rgb(239, 246, 255);
					}
				}
			}

			.contenttit {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.tipsbox {
				margin-top: 16rpx;
				font-size: 12rpx;

				.tipsborder {
					border: 1rpx solid rgb(108, 126, 205);
					border-radius: 10rpx;
					color: rgb(108, 126, 205);
					background-color: rgb(239, 246, 255);
				}
			}
		}
	}

	.searchbox {
		.searchimg {
			width: 60rpx;
			height: 40rpx;
			border-right: 1rpx solid #999;

			image {
				width: 40rpx;
			}
		}

		.selectbox {
			display: flex;
			overflow: auto;

			.selectitem,
			.selectitem1 {
				flex-grow: 0;
				flex-shrink: 0;
				font-size: 24rpx;
				color: #999;
				margin: 0 10rpx;
				border-radius: 40rpx;
				background-color: rgb(246, 246, 246);
			}

			.selectitem {
				color: #fff;
				background-color: rgb(0, 203, 211);
			}
		}
	}

	.toptitbox {
		width: 100%;
		border-bottom: 1rpx solid #f6f6f6;
	}

	.rightbox {
		width: 260rpx;
		background-color: aqua;
		height: 140rpx;
	}



	::v-deep  .u-action {
		color: #fff !important;
	}







	.midActive {
		// border-bottom: 10rpx solid #44ACFF;
		color: #000;
		font-weight: 600;

		.line {
			width: 40%;
			height: 10rpx;
			position: relative;
			top: 9rpx;
			left: 30%;
			background-color: rgb(0, 203, 211);
		}
	}
</style>
